/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * 知启蒙Servlet兼容库（zhiqim_servlet）在LGPL3.0协议下开源：https://www.zhiqim.com/gitcan/zhiqim/zhiqim_servlet.htm
 *
 * This file is part of [zhiqim_servlet].
 * 
 * [zhiqim_servlet] is free software: you can redistribute
 * it and/or modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * [zhiqim_servlet] is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with [zhiqim_servlet].
 * If not, see <http://www.gnu.org/licenses/>.
 */
package org.zhiqim.calendar.action;

import org.zhiqim.calendar.dbo.ZmrCalendar;

import org.zhiqim.kernel.Global;
import org.zhiqim.httpd.HttpRequest;
import org.zhiqim.httpd.context.extend.ValidateAction;
import org.zhiqim.orm.ZTable;
import org.zhiqim.httpd.validate.ones.IsNotEmpty;

/**
 * 日历休息日/工作日数据删除
 *
 * @version v1.0.0 @author zhichenggang 2014-3-21 新建与整理
 */
public class CalendarDeleteAction extends ValidateAction
{
    @Override
    protected void validate(HttpRequest request)
    {
        request.addValidate(new IsNotEmpty("calendarDate", "请选择一个选项"));
    }

    @Override
    protected void perform(HttpRequest request) throws Exception
    {
        int calendarDate = request.getParameterInt("calendarDate");
        ZmrCalendar item = Global.get(ZTable.class).item(ZmrCalendar.class, calendarDate);
        if(item == null)
        {
            request.returnHistory("日历不存在，请重新选择");
            return;
        }
        
        Global.get(ZTable.class).delete(ZmrCalendar.class, calendarDate);
    }
}
